<?php
/**
 * This factory class returns desired email trasport class for sending emils.
 * The settings for different transport are taken from module settings
 *
 * @author Ishtiaque Shahrier <md.ishtiaque@newgenbd.net>
 * @package email
 * @subpackage libraries
 */
include_once 'swift_mailer_4_0_6/lib/swift_required.php';
class transport_factory_l_email {

    public static function get_transport($protocol){
        $transport=NULL;
        switch ($protocol) {
            case transport_type_m_email::SMTP:
                $transport = transport_factory_l_email::__build_smtp();
                break;
            case transport_type_m_email::POP:
                break;
            case transport_type_m_email::MAIL:
                break;
            default:
                show_error("Invalid ptotocol for mail transport layer ".__CLASS__);
                break;
        }
        return $transport;
    }

    private static function __build_smtp(){

        $module = get_module_obj("email");
        
        $server = $module->get_setting("out_smtp_server");
        $port   = $module->get_setting("out_stmp_port");
        $ssl    = ((int)$module->get_setting("out_is_ssl")) ? TRUE : FALSE;
        $user   = $module->get_setting("out_smtp_user");
        $pass   = $module->get_setting("out_smtp_pass");

        $transport = Swift_SmtpTransport::newInstance($server, $port,($ssl===TRUE? 'ssl':NULL));
        $transport->setUsername($user);
        $transport->setPassword($pass);

        return $transport;

    }
}
?>
